package com.bytedance.article.common.c;

import com.bytedance.common.utility.Logger;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;

public final class JSONObjectWrapper {
    public JSONObject jo;

    public JSONObjectWrapper() {
        if (this.jo == null) {
            this.jo = new JSONObject();
        }
    }

    public final JSONObjectWrapper put(String key, Object value) {
        try {
            this.jo.put(key, value);
        } catch (JSONException e) {
            Logger.throwExceptionInDebug(e);
        }

        return this;
    }

    public final JSONObjectWrapper put(JSONObject input) {
        if (input != null) {
            Iterator<String> iterator = input.keys();
            while (iterator.hasNext()) {
                try {
                    String key = iterator.next();
                    this.jo.put(key, input.get(key));
                } catch (JSONException e) {
                    Logger.throwExceptionInDebug(e);
                }
            }
        }

        return this;
    }
}

